﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AutoIE
{
    class PluProcessor : BasicProcessor
    {
        public override void Run()
        {
            var url = "http://bbs.plu.cn/forum-3-1.html";
            Initialize(url, "a.xlsx", true);
            // login
            var p = GotoUrl("http://login.plu.cn/user/login?returnurl=http%3A%2F%2Fbbs.plu.cn%2Fforum-3-1.html");
            p.Fill(new object[] { "", "nickname", "", "mot", "5", "questionid","", "prom" });
            p.Click("login_submit");
            //Post("http://login.plu.cn/user/login", "name=wsguest&password=abcddcba&questionid=5&answer=T61&autologin=1&returnurl=http://bbs.plu.cn/forum-3-1.html");
            var p1 = WaitUrl(url);
            var dg = new string[]{"http://bbs.plu.cn/plugin.php?id=mzg_advertise:index&mod=view&did=3",
	"http://bbs.plu.cn/plugin.php?id=mzg_advertise:index&mod=view&did=5",
	"http://bbs.plu.cn/plugin.php?id=mzg_advertise:index&mod=view&did=11",
	 "http://bbs.plu.cn/plugin.php?id=mzg_advertise:index&mod=view&did=9",};
            for (int i = 0; i < dg.Length; i++)
            {
                //p1.Navigate(dg[i]);
                //Wait(3000);
            }

            Data.MoveFirst();

            while (true)
            {
                string nid = p1.GetElemUniqueID("^<th class=\"new\">[\\s\\S]*</th>$");
                if (!string.IsNullOrEmpty(nid))
                {
                    string id = p1.GetElemUniqueID("^<a href=\"thread-\\d+-1-1\\.html\" onclick=\"atarget\\(this\\)\" class=\"xst\" >.*</a>$");
                    p1.Click(id);
                    Wait();
                    Wait(2000);
                    var m1 = new object[] { Data["回复"], "fastpostmessage" };
                    p1.Fill(m1);
                    p1.Click("fastpostsubmit");
                    if(!Data.MoveNext())
                        break;
                    OutputLine("posted :" + Data["回复"]);
                    OutputLine("Wait 5s ...");
                    Wait(5000);
                }
                p1.Navigate(url);
                OutputLine("Wait 10s ...");
                Wait(10000);
            }
            Data.Save();
        }
    }
}
